package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.HourWageAdapter;
import flc.ast.bean.HourWageBean;
import flc.ast.databinding.ActivityHourWageBinding;
import flc.ast.utils.AppSpUtils;

public class HourWageActivity extends BaseAc<ActivityHourWageBinding> {

    private HourWageAdapter hourWageAdapter;
    private List<HourWageBean> listShow = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.activity_hour_wage;
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    protected void initView() {
        mDataBinding.ivHourWageBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvAdd.setOnClickListener(this);

        mDataBinding.rvWageList.setLayoutManager(new LinearLayoutManager(mContext));
        hourWageAdapter = new HourWageAdapter();
        mDataBinding.rvWageList.setAdapter(hourWageAdapter);
        hourWageAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvAdd:
                AddHourWageActivity.type = 1;
                startActivity(AddHourWageActivity.class);
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        AddHourWageActivity.listWage = listShow;
        AddHourWageActivity.selPosition = position;
        AddHourWageActivity.type = 0;
        startActivity(AddHourWageActivity.class);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void getData() {
        listShow.clear();
        List<HourWageBean> listSp = AppSpUtils.getWageList();
        if (listSp != null && listSp.size() != 0) {
            listShow.addAll(listSp);
            hourWageAdapter.setList(listShow);
        }
    }

}